//
//  ViewController.m
//  SwitchDemo
//
//  Created by Xwoder on 2017/9/11.
//  Copyright © 2017年 Xwoder. All rights reserved.
//

#import "ViewController.h"
#import "JQKSwitch.h"

@interface ViewController () <JQKSwitchDelegate>

@property (weak, nonatomic) IBOutlet JQKSwitch *mySwitch;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.mySwitch.delegate = self;
    
    self.mySwitch.valueChangedBlock = ^(BOOL isChangedByUser) {
        NSLog(@"isChangedByUser = %@", isChangedByUser ? @"YES" : @"NO");
    };
}

- (IBAction)switchTaped:(JQKSwitch *)sender {
    [self func];
}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.mySwitch setOn:!self.mySwitch.isOn animated:YES];
    [self func];
}

- (void)func {
    NSLog(@"%s, %d", __FUNCTION__, self.mySwitch.changedByUser);
}

#pragma mark - JQKSwitchDelegate

- (void)jqkSwitch:(JQKSwitch *)jqkSwitch valueChangedByUser:(BOOL)isChangedByUser {
    NSLog(@"%s, %@", __FUNCTION__, isChangedByUser ? @"YES" : @"NO");
}

@end
